<?php

$get = array_merge($_GET, $_POST);

$img = $get["img"];
$w = (int)$get["w"];
$h = (int)$get["h"];
$w2 = $w; $h2 = $h;

$img = new Imagick($get["img"]);
$w1 = $img->getImageWidth();
$h1 = $img->getImageHeight();

if($w2>0 && $w2!=$w1){
	$h2 = $w2*$h1/$w1;
}
if($h2>0 && $h2!=$h1){
	$w2 = $w1*$h2/$h1;
}

if($w2>0 && $h2>0){
	$img->adaptiveResizeImage($w2,$h2);
}
header("Content-Type: image/".strtolower($img->getImageFormat()));
echo $img;

?>